package com.ziguang.redwood.admin.service;

import java.util.List;

import com.jfinal.aop.Before;
import com.jfinal.log.Log4jLog;
import com.jfinal.plugin.activerecord.Db;
import com.jfinal.plugin.activerecord.Record;
import com.jfinal.plugin.activerecord.tx.Tx;
import com.ziguang.common.SysConstant;

public class HomeService {
	private static final Log4jLog log = Log4jLog.getLog(HomeService.class);
	
	public static final HomeService me = new HomeService();
	
	/**
	 * 获取新闻动态数据
	 */
	public List<Record> index(){
		List<Record> data=Db.find("select h.* from rw_home h order by h.sort");
		return data;
	}
	
	
	/**
	 * 获取当前数据
	 */
	public Record QueryEdit(String id){
		Record data = Db.findFirst("select h.* from rw_home h where h.id = ? order by h.sort",id);
		return data;
	}
	
	/**
	 * 保存编辑数据
	 */
	@Before(Tx.class)
	public void save(String id,String sort,String homeImg){
		log.info("==="+homeImg+"==="+id+"==="+sort);
		Db.update("UPDATE rw_home SET img = ?,sort = ? WHERE id = ?",homeImg,sort,id);
	}
	
}
